package com.example.protestgps;

import org.json.JSONArray;
import org.json.JSONObject;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;

import android.app.Dialog;
import android.content.Context;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;

public class ShowMapandHttpPostVoice extends FragmentActivity {
	private LocationManager lm;
	GoogleMap myMap;
	public double latchange = 0;
	public double lngchange = 0;
	LatLng start2;
	public Context con;

	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		setContentView(R.layout.mapvoice);

		int status = GooglePlayServicesUtil
				.isGooglePlayServicesAvailable(getBaseContext());
		if (status != ConnectionResult.SUCCESS) {

			int requestCode = 10;
			Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this,
					requestCode);
			dialog.show();
		}

		else {
			lm = (LocationManager) getSystemService(LOCATION_SERVICE);
			con = new ShowMapandHttpPostVoice();
			GetLocation local = new GetLocation(lm, this, myMap);
			latchange = local.GetLat();
			lngchange = local.GetLng();
			start2 = new LatLng(latchange, lngchange);
			Log.d("latchange", "" + latchange);
			SupportMapFragment mySupport = (SupportMapFragment) getSupportFragmentManager()
					.findFragmentById(R.id.map_canvas);
			myMap = mySupport.getMap();
			myMap.setMyLocationEnabled(true);
			CallHTTP(latchange, lngchange);
			posteremer(latchange, lngchange);

		}
		
	}
	
	
	public void CallHTTP(double curlat, double curlng) {
		AsyncTask<String, String, String> AsyncTask1;
		JSONArray JsonArr;
		JSONObject JSONOBJ;
		LatLng despoint;
		HttpPostSvr task = new HttpPostSvr();
		// task.setdata();
		task.curpoint(curlat, curlng,myMap);
		AsyncTask1 = task.postter
				.execute("http://192.168.1.101/myexample/mytest1.php");
	
	}
	
	

	public void recdata(double _lat,double _lng,double curlat,double curlng,GoogleMap Map){
		Log.d("_lat",""+_lat);
		LatLng curpoint = new LatLng(curlat, curlng);
		LatLng despoint= new LatLng(_lat, _lng);
		Log.d("despoint",""+despoint);
		Log.d("curpoint",""+curpoint);
		Log.d("Map",""+Map);
		Router routerr1 = new Router(Map, curpoint, despoint);
		
	}
	
	
	public void posteremer(double curlat, double curlng) {
		AsyncTask<String, String, String> AsyncTask1;
		JSONObject JSONOBJ;
		LatLng despoint;
		PostEmerVoice post = new PostEmerVoice();
		post.curpoint(curlat, curlng);
		AsyncTask1 = post.postsemer
				.execute("http://192.168.1.101/myexample/insertvoice.php");
		Log.d("a1", "a1");
	}

}
